package com.geekaca.testthread.wokr2;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class Test1 {
    public static void main(String[] args) {
        /**
         * 模拟卖票 只有20张票,3 个窗口
         */

        ArrayBlockingQueue waitQueue = new ArrayBlockingQueue<>(5);

        // 线程池创建
        ThreadPoolExecutor threadPool = new ThreadPoolExecutor(5,
                20,
                20,
                TimeUnit.SECONDS,
                waitQueue,
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());

        for (int i = 0; i < 20; i++) {

            try {
                threadPool.execute(new SellTicket());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }


        threadPool.shutdown();


    }
}
